<?php

include_once '../classes/includes/ConnectBD.php';
include_once '../classes/includes/NoSqlInjection.php';

class ContatoDAO{

 	 private $connect;
	 
 	 public function __construct(){
	 	if($this->connect == null){
	 	$this->connect =  new ConnectBD();
	 	}
	 }	
	
	 public function __destruct(){

	 	if($this->connect != null){
		$this->connect->__destruct();
	 	}
	 }
	 
	public function getContatoUsuario($user){
	 		 	
	 	//monta usuario completo
	 	$consulta2 = $this->connect->getUsuario($user);
		 	
			if(mysql_num_rows($consulta2) > 0){
						 	
					 		while($usuarios = mysql_fetch_array($consulta2)){
						 		
					 			$pNome = $usuarios['nome'];
						 		$pSobrenome = $usuarios['sobrenome'];
						 		
					 		}
						 				 
			}else{
		 	return null;
		 	}
		 
		$user->setNome($pNome);
		$user->setSobrenome($pSobrenome);
		
		return $user;
		
	}
	
	public function getContatos($user){
		
		$consulta = $this->connect->getQueryWithParamns("contatos", "*", "cod_usuario='".$user->getId()."' ");
			if(mysql_num_rows($consulta) > 0){
				return $consulta;
				
			}else{
				return "0";
			}
		
	} 

	
}